unit UCOI0010P5;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
  System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, UGlobal,
  cxGraphics, cxControls, cxLookAndFeels, cxLookAndFeelPainters, cxStyles,
  cxCustomData, cxFilter, cxData, cxDataStorage, cxEdit, DB, cxDBData,
  cxTextEdit, cxCurrencyEdit, cxCheckBox, cxCheckComboBox, cxContainer,
  Datasnap.DBClient, Vcl.StdCtrls, cxButtonEdit, cxDropDownEdit, cxMaskEdit,
  cxImageComboBox, Vcl.Buttons, fsButton, cxGridLevel, cxGridCustomTableView,
  cxGridTableView, cxGridDBTableView, cxClasses, cxGridCustomView, cxGrid,
   Vcl.ExtCtrls, fsPanel, cxGridBandedTableView, cxGridDBBandedTableView,
  UFrameChkCombo, UFrameCode, fsLabel;

type
  TFCOI0010P5 = class(TForm)
    PnlButton: TfsPanel;
    BtnOpen: TfsButton;
    BtnApply: TfsButton;
    BtnInit: TfsButton;
    CDS1: TClientDataSet;
    DS1: TDataSource;
    PnlSearch: TfsPanel;
    BtnClose: TfsButton;
    LblUSERIDNM: TfsLabel;
    EdtUSERIDNM: TcxTextEdit;
    FrmUSERIDNM: TFrmCode;
    FrmUSERGBCD: TFrmChkCombo;
    DBGrid1: TcxGrid;
    DBGridView1: TcxGridDBBandedTableView;
    DBGridView1Column1: TcxGridDBBandedColumn;
    DBGridView1Column2: TcxGridDBBandedColumn;
    DBGridView1Column3: TcxGridDBBandedColumn;
    DBGridView1Column4: TcxGridDBBandedColumn;
    DBGridView1Column5: TcxGridDBBandedColumn;
    DBGridLevel1: TcxGridLevel;
    Edit1: TEdit;
    procedure FormCreate(Sender: TObject);
    procedure FormKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure FormDestroy(Sender: TObject);
    procedure DBGridView1DblClick(Sender: TObject);
    procedure BtnOpenClick(Sender: TObject);
    procedure EdtSTORECDNMPropertiesChange(Sender: TObject);
    procedure OpenCDS;
    procedure BtnInitClick(Sender: TObject);
    procedure BtnApplyClick(Sender: TObject);
    procedure FrmCHARGEUSEREdtCodePropertiesChange(Sender: TObject);
    procedure FrmSHOPCDEdtCodePropertiesChange(Sender: TObject);
    procedure BtnCloseClick(Sender: TObject);
    procedure FrmUSERIDNMEdtCodePropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure EdtUSERIDNMKeyPress(Sender: TObject; var Key: Char);
    procedure FrmUSERGBCDCmbCodePropertiesEditValueChanged(Sender: TObject);
    procedure DBGridView1Column1HeaderClick(Sender: TObject);

  private
    { Private declarations }
  public
    { Public declarations }
    Global: IGlobal;
    procedure Init;
  end;

var
  FCOI0010P5: TFCOI0010P5;

implementation

uses UDataModuleClient;

{$R *.dfm}


procedure TFCOI0010P5.Init;
begin
//  Global.CheckComboBoxAddItem(FrmBRAND.CmbCode, Format(Global.GetSql('CBSQL_BRAND' ),[Global.GetSysParam('DATAAREAID'), '', Global.StrToInStr('')]));
  FrmUSERGBCD.AddItems(Format(Global.GetSql('CBSQL_CODE'), ['SY', '00410', 'Y']));

  Global.ImageComboBoxAddItem(TcxImageComboBoxProperties(DBGridView1.GetColumnByFieldName('USERGBCD').Properties),
    Format(Global.GetSql('CBSQL_CODE'), ['SY', '00410', '']));

end;

procedure TFCOI0010P5.FormCreate(Sender: TObject);
begin
//
end;

procedure TFCOI0010P5.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin

  if Shift = [] then
  begin
    case Key of
      vk_F3     : if BtnOpen.Enabled  then BtnOpen.Click;
      vk_F12    : if BtnInit.Enabled  then BtnInit.Click;
      VK_RETURN : Perform(CM_DIALOGKEY, VK_TAB, 0);
      VK_ESCAPE : ModalResult := mrCancel;
    end;
  end;

end;

procedure TFCOI0010P5.FrmCHARGEUSEREdtCodePropertiesChange(Sender: TObject);
begin
  BtnInitClick(nil);
end;

procedure TFCOI0010P5.FrmSHOPCDEdtCodePropertiesChange(Sender: TObject);
begin
  BtnInitClick(nil);
end;

procedure TFCOI0010P5.FrmUSERGBCDCmbCodePropertiesEditValueChanged(
  Sender: TObject);
begin
  // EditChangedEvent(False);
  try
    if CDS1.Active then
      CDS1.Close;

    if Sender = nil then
    begin
      Global.ClearControls(PnlSearch);
      Global.FirstControlSetFocus(Self);
    end;
  finally
    FrmUSERIDNM.ClearFrame;
    EdtUSERIDNM.Clear;
  end;

end;

procedure TFCOI0010P5.FrmUSERIDNMEdtCodePropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
VAR
  StrUSERGB : String;
begin
  StrUSERGB := FrmUSERGBCD.CmbCode.EditValue;
  if FrmUSERGBCD.CmbCode.EditValue = '1' then
  begin
    Global.CodeHelp(Format(Global.GetSql('HSQL_USERIDNM', COPY(SELF.Name,1,8)), ['%%0:s%', '%1:s', StrUSERGB])
      , ['', Global.GetSysParam('COMPANYCD')]
      , [FrmUSERIDNM.EdtCode, FrmUSERIDNM.LblCodeNm], ['USERID', 'USERNM'], False, 2, -1);

  end
  else if FrmUSERGBCD.CmbCode.EditValue = '2' then
  begin
    Global.CodeHelp(Format(Global.GetSql('HSQL_SHOPCD1', 'COMMON'), ['%%0:s%', '%1:s'])
      , ['', Global.GetSysParam('COMPANYCD')]
      , [FrmUSERIDNM.EdtCode, FrmUSERIDNM.LblCodeNm], ['SHOPCD', 'SHOPNM'], False, 2, -1);
  end
  else if FrmUSERGBCD.CmbCode.EditValue = '3' then
  begin
    Global.CodeHelp(Format(Global.GetSql('HSQL_USERIDNM', COPY(SELF.Name,1,8)), ['%%0:s%', '%1:s', StrUSERGB])
      , ['', Global.GetSysParam('COMPANYCD')]
      , [FrmUSERIDNM.EdtCode, FrmUSERIDNM.LblCodeNm], ['USERID', 'USERNM'], False, 2, -1);

  end;

end;

procedure TFCOI0010P5.FormDestroy(Sender: TObject);
begin
  CDS1.Close;
end;

procedure TFCOI0010P5.DBGridView1Column1HeaderClick(Sender: TObject);
begin
  Global.ChoiceAndCancelGridData(Sender);
end;

procedure TFCOI0010P5.DBGridView1DblClick(Sender: TObject);
begin
  if (Not CDS1.Active ) or (CDS1.IsEmpty) then Exit;

  ModalResult := mrOk;
end;

procedure TFCOI0010P5.BtnApplyClick(Sender: TObject);
begin
  if (Not CDS1.Active ) or (CDS1.IsEmpty) then Exit;

  ModalResult := mrOk;
end;

procedure TFCOI0010P5.BtnCloseClick(Sender: TObject);
begin
  ModalResult := mrClose;
end;

procedure TFCOI0010P5.BtnInitClick(Sender: TObject);
begin
  CDS1.Close;

  if Assigned(Sender) then
  begin
    Global.ClearControls(PnlSearch);
    Global.FirstControlSetFocus(PnlSearch);
  end;
end;

procedure TFCOI0010P5.BtnOpenClick(Sender: TObject);
begin
  Global.ChkFrameValue(PnlSearch);

  Global.StartJob;

  CDS1.DisableControls;
  try

    OpenCDS;

    if CDS1.IsEmpty then
    begin
      Global.ShowCustomMessage(Global.GetMessage('msg_Q03'), 3);
      Global.FirstControlSetFocus(PnlSearch);
      Exit;
    end;

  finally
    CDS1.EnableControls;

    if Not CDS1.IsEmpty then
    begin
      DBGridView1.DataController.FocusedRowIndex := 0;
      DBGridView1.DataController.SelectRows(0,0);
    end;

  end;
  DBGrid1.SetFocus;

end;

procedure TFCOI0010P5.OpenCDS;
var
  subSQL  : string;
begin

  Global.StartJob;
  Global.SQLConnection.Connected := True;

  try
    with CDS1 do
    begin
      Close;
      CommandText := Format(Global.GetSql('OPENP3', COPY(Self.Name,1,8)), [
        Global.GetSysParam('COMPANYCD')
        , GLOBAL.GetCheckedShortDescription(FrmUSERGBCD.CmbCode,false)
        , GLOBAL.GetCheckedShortDescription(FrmUSERGBCD.CmbCode)
        , FrmUSERIDNM.EdtCode.Text
        , EdtUSERIDNM.Text
        ]);

EDIT1.Text := COMMANDTEXT;
      Open;

      if IsEmpty then
      begin
        Global.ShowCustomMessage(Global.GetMessage('MSG_Q03'), 3);
        exit;
      end;
    end;

  finally
    Global.SQLConnection.Connected := False;
  end;


end;

procedure TFCOI0010P5.EdtSTORECDNMPropertiesChange(Sender: TObject);
begin
    if CDS1.Active then CDS1.Close;
end;

procedure TFCOI0010P5.EdtUSERIDNMKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then
  begin
    Key := #0;
    if Sender = EdtUSERIDNM then  BtnOpen.Click
    else GetParentForm(TControl(Sender)).Perform(CM_DIALOGKEY, VK_TAB, 0);
  end;
end;

end.
